// pages/OnePlaylist/OnePlaylist.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        name:'日语',
        isshow:false,
        limit:18,
        offset:0,
        playlist:[],
    },
    async  getPlaylist(){
        this.setData({
            isshow:true
        })
        wx.showLoading({
            title: 'loading',
          })
          const res = await wx.p.request({
              url:`${wx.root}/top/playlist`,
              data:{  
                  cat:this.data.name,
                  limit:this.data.limit,
                  offset:this.data.offset*this.data.limit
              }
          })
          for (let index = 0; index < res.data.playlists.length; index++) {
            const item = res.data.playlists[index];
            if(item.playCount >= 100000000) 
                item.count = parseInt(item.playCount/100000000)+'亿'
            else if(item.playCount >= 10000)
                item.count = parseInt(item.playCount/10000)+'万'
            else item.count = item.playCount+''
        }
          wx.hideLoading({
            success: () => {
                this.setData({
                    playlist:[...this.data.playlist,...res.data.playlists],
                    offset:this.data.offset+1,
                    isshow:false,
                    limit:30,
                })
            },
          })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            name:options.name
        })

        wx.setNavigationBarTitle({
            title: '歌单-'+this.data.name,
         })
         this.getPlaylist()
    },
    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.isshow == false)
        this.getPlaylist()
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})